package com.ktgj.customer.api.factory;

import com.ktgj.common.core.domain.R;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.customer.api.domain.Card;
import com.ktgj.customer.api.domain.PassengerDocuments;
import com.ktgj.customer.api.RemoteCustomerService;
import com.ktgj.customer.api.domain.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 *  * 会员服务降级处理
 * @author ruoyi
 */
@Component
public class RemoteCustomerFallbackFactory implements FallbackFactory<RemoteCustomerService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteCustomerFallbackFactory.class);

    @Override
    public RemoteCustomerService create(Throwable cause) {
        log.error("会员服务调用失败:{}", cause.getMessage());
        return new RemoteCustomerService() {

            /**
             * 根据部门id获取部门信息
             * @param deptId
             * @return
             */
            @Override
            public R<Department> getDepartmentInfo(Long deptId) {
                return R.fail("获取部门失败" + cause.getMessage());
            }

            /**
             * 根据会员id获取会员信息
             * @param customerId
             * @return
             */
            @Override
            public R<Customer> getCustomerInfo(Long customerId) {
                return R.fail("获取会员信息失败" + cause.getMessage());
            }

            @Override
            public R<Customer> getCustomerId(Long customerId) {
                return R.fail("获取会员信息失败" + cause.getMessage());
            }

            /**
             * 根据token获取员工信息
             */
            @Override
            public R<Employee> getLoginEmployeeByToken(String token) {
                return R.fail("获取员工信息失败" + cause.getMessage());
            }

            @Override
            public R<Employee> getInfoById(Map<String, Long> map) {
                return R.fail("获取员工信息失败" + cause.getMessage());
            }

            /**
             * 用户端app根据token获取用户信息
             */
            @Override
            public R<Customer> getLoginCustomerByToken(String token) {
                return R.fail("获取会员信息失败" + cause.getMessage());
            }

            /**
             *
             * 花费积分、核销优惠卷、扣除预留款
             *  使用时判断R<String>.smg.equals("success")
             *
             * @param customerId 会员id
             * @param creditsNum 要扣减的积分
             * @param orderType 订单类型
             * @param orderId 订单id
             * @param orderSourceDesc 订单描述（客户端展示使用），例如机票 显示航程+航班号
             * @param couponId 使用优惠卷的id
             * @param usedDeposit 要扣除的预留款金额
             * @param employeeId 操作员工id（用户端没有操作员工，入参1L写死）
             * @return
             */
            @Override
            public R<String> spend(@RequestParam("customerId") Long customerId, @RequestParam("creditsNum") Long creditsNum, @RequestParam("orderType") String orderType,
                                   @RequestParam("orderId") Long orderId, @RequestParam("orderSourceDesc") String orderSourceDesc, @RequestParam("couponId") Long couponId,
                                   @RequestParam("usedDeposit") BigDecimal usedDeposit, @RequestParam("employeeId") Long employeeId) {
                return R.fail("花费积分、核销优惠卷失败" + cause.getMessage());
            }

            /**
             * 获取会员积分
             * @param token
             * @return
             */
            @Override
            public R<Long> queyUserCreditsNumByToken(String token) {
                return R.fail("获取会员积分失败" + cause.getMessage());
            }

            @Override
            public R<Long> queyUserCreditsNumByCustomerId(Long customerId) {
                return R.fail("获取会员积分失败" + cause.getMessage());
            }

            /**
             * 根据会员卡id获取会员卡信息
             * @param cardCode
             * @return
             */
            @Override
            public CustomerCard selectCustomerCard(String cardCode) {
                return null;
            }

            /**
             * 获取会员预留款
             * @param token
             * @return
             */
            @Override
            public R<Long> queyUserDepositBusinessByToken(String token) {
                return R.fail("获取会员预留款失败" + cause.getMessage());
            }

            @Override
            public R<Long> selectAvailableGoldByCustomerId(Long customerId) {
                return R.fail("获取会员预留款失败" + cause.getMessage());
            }

            /**
             * 根据金额推荐最优优惠券
             * @param token
             * @return
             */
            @Override
            public R<CouponDto> queyUserCouponByToken(String token, BigDecimal money) {
                return R.fail("获取会员优惠券信息失败" + cause.getMessage());
            }

            @Override
            public R<CouponDto> queyUserCouponById(Long customerId, BigDecimal money) {
                log.error("获取会员优惠券信息失败", cause.getMessage());
                return null;
            }

            @Override
            public CustomerCard selectVipOrder(Long customerId) {
                log.error("获取卡id失败", cause.getMessage());
                return null;
            }

            @Override
            public BusinessOrder selectBusinessOrderByOrdernum(String ordernum) {
                log.error("获取订单号失败", cause.getMessage());
                return null;
            }

            @Override
            public List<CustomerCard> queryCardIdByCustomerId(Long customerId) {
                log.error("获取会员卡号失败", cause.getMessage());
                return null;
            }

            @Override
            public List<CommonPassengerApi> queryPassengerByCustomerId(Long customerId, Long commonTrvelersId, String certificateType) {
                log.error("获取乘客信息失败", cause.getMessage());
                return null;
            }

            @Override
            public List<AssistProductApi> queryAssistProductList(@RequestBody Map<String, Object> map) {
                log.error("获取辅营产品信息失败", cause.getMessage());
                return null;
            }

            @Override
            public AssistProductVoApi assistProduct(Map<String, Object> map) {
                log.error("获取辅营产品信息失败", cause.getMessage());
                return null;
            }

            @Override
            public int updatetrainPassword(Long customerId, String trainPassword) {
                log.error("修改12306密码失败", cause.getMessage());
                return 0;
            }

            @Override
            public int update(Customer customer) {
                return 0;
            }

            @Override
            public R<CustomeraccountApi> queryAccountIdAndAccountPassword(Long customerId, String accountType) {
                return R.fail("获取会员12306账号失败！" + cause.getMessage());
            }

            @Override
            public int insert(CustomeraccountApi customeraccount) {
                return 0;
            }

            @Override
            public int updateAccountPassword(CustomeraccountApi customeraccount) {
                return 0;
            }

            @Override
            public R<Coupon> couponById(Long couponId) {
                return R.fail("获取优惠券金额信息失败！" + cause.getMessage());
            }

            @Override
            public R<CouponBO> couponByCustomerRightDetailId(Long customerRightDetailId) {
                return R.fail("根据会员权益id查询优惠卷信息失败！" + cause.getMessage());
            }

            @Override
            public R<AssistProductApi> queryAssistProduct(Long id) {
                return R.fail("获取辅营产品信息失败！" + cause.getMessage());
            }

            @Override
            public Customer getCustomerByMobile(String moblieId)
            {
                log.error("查询会员信息失败", cause.getMessage());
                return null;
            }

            @Override
            public String delFrequentTraveler(String token, Long commonTrvelersId) {
                log.error("删除乘车人异常", cause.getMessage());
                return null;
            }

            @Override
            public int insertCommonTravelers(String token, PassengerInformationApi information) {
                log.error("添加乘车人异常", cause.getMessage());
                return 0;
            }

            @Override
            public int insertCommonTravelersCrm(Long customerId, PassengerInformationApi information) {
                log.error("添加乘车人异常", cause.getMessage());
                return 0;
            }

            @Override
            public int edits(CommonTravelersApi commonTravelers) {
                log.error("修改乘车人异常", cause.getMessage());
                return 0;
            }

            @Override
            public AjaxResult depositBusiness(HttpServletRequest request) {
                log.error("修改乘车人异常", cause.getMessage());
                return null;
            }

            @Override
            public CalculationDTO calculationRemotely(CalculationVOApi calculationVOApi) {
                log.error("价格计算异常", cause.getMessage());
                return null;
            }

            @Override
            public List<CommonTravelers> fileCommonTravelers(Map<String, Object> map) {
                log.error("获取常用旅客异常", cause.getMessage());
                return null;
            }

            @Override
            public List<PassengerDocuments> selectDocumentsByCommontrvelersId(Map<String, Object> map) {
                log.error("获取证件异常", cause.getMessage());
                return null;
            }

            @Override
            public R<PassengerDocuments> backSelectPassengerDocumentsBack(Long commontrvelersId) {
                return R.fail("常用旅客的证件信息失败！" + cause.getMessage());
            }

            @Override
            public String selectBankLike(Map<String, Object> map) {
                log.error("获取银行代码异常", cause.getMessage());
                return null;
            }

            @Override
            public Long customerByCustomerName(VipCustomerVo vipCustomerVo) {
                log.error("获取会员id异常", cause.getMessage());
                return null;
            }

            @Override
            public CustomerCard customerCardList(Map<String, Object> map) {
                log.error("获取会员卡信息异常", cause.getMessage());
                return null;
            }

            @Override
            public List<Customer> customerList(Customer customer) {
                log.error("获取会员信息异常", cause.getMessage());
                return null;
            }

            @Override
            public Card cardInfo(Map<String, Object> map) {
                log.error("获取会员卡信息异常", cause.getMessage());
                return null;
            }

            @Override
            public BankCard selectBackCardNum(Map<String, Object> map) {
                log.error("获取银行卡信息异常", cause.getMessage());
                return null;
            }

            @Override
            public String backCard(Map<String, Object> map) {
                log.error("获取银行卡代码异常", cause.getMessage());
                return null;
            }

            @Override
            public List<HotelCouponVo> couponList(Map<String, Object> map) {
                log.error("获取优惠券异常", cause.getMessage());
                return null;
            }

            @Override
            public int addCustomerMessage(Map<String, String> map) {
                log.error("会员信息添加异常", cause.getMessage());
                return 0;
            }

            @Override
            public int updCustomerMessage(Map<String, String> map) {
                log.error("会员信息修改异常", cause.getMessage());
                return 0;
            }

            @Override
            public BankCard backCardNum(String cardNumber) {
                log.error("获取银行卡信息失败", cause.getMessage());
                return null;
            }

            @Override
            public int bankCard(BankCard bankCard) {
                log.error("新增银行卡信息失败", cause.getMessage());
                return 0;
            }

            @Override
            public CustomerIdVoApi customerIdApi(CustomerIdVoApi customerIdVo) {
                log.error("获取会员卡号失败", cause.getMessage());
                return null;
            }

            @Override
            public int refund(DepositBusinessApi depositBusiness) {
                log.error("会员退款添加预留款记录失败", cause.getMessage());
                return 0;
            }

            @Override
            public List<Long> employeeIdList(Map<String, Object> map) {
                log.error("获取员工id失败", cause.getMessage());
                return null;
            }

            @Override
            public List<Employee> getOnlineEmployeeList() {
                log.error("获取在线员工信息失败", cause.getMessage());
                return null;
            }

            @Override
            public List<Employee> getEmployeeListByIds(List<Long> lstIds)
            {
                log.error("获取员工信息列表失败", cause.getMessage());
                return null;
            }

            @Override
            public Employee employeeNameList(Map<String, Object> map) {
                log.error("获取员工姓名失败", cause.getMessage());
                return null;
            }

            @Override
            public Long addReserveMoney(DepositBusinessApi depositBusinessApi) {
                log.error("调用添加预留款记录失败", cause.getMessage());
                return 0l;
            }

            @Override
            public List<Long> employeeVipIdList(Map<String, Object> map) {
                log.error("获取员工id失败", cause.getMessage());
                return null;
            }

            @Override
            public Department department(Map<String, Object> map) {
                log.error("获取部门名称失败", cause.getMessage());
                return null;
            }

            @Override
            public Department deptName(Map<String, Object> map) {
                log.error("获取部门名称失败", cause.getMessage());
                return null;
            }

            @Override
            public BankApi bankNames(Map<String, Object> map) {
                log.error("获取银行信息失败", cause.getMessage());
                return null;
            }

            @Override
            public R<AjaxResult> add(FinanceOrderRefundment financeOrderRefundment) {
                return R.fail("新增财务会员退款信息失败！" + cause.getMessage());
            }

            @Override
            public InsuranceReturnVoApi insertInsuranceRecordBack(ProductVoApi productVo) {
                log.error("开保失败", cause.getMessage());
                return null;
            }

            @Override
            public int save(FinanceOrderRefundment financeOrderRefundment) {
                log.error("添加会员退款信息失败", cause.getMessage());
                return 0;
            }

            @Override
            public int number() {
                log.error("获取批次号失败", cause.getMessage());
                return 0;
            }

            @Override
            public boolean updateStart(InsuranceRecord insuranceRecord) {
                log.error("修改保险状态调用失败", cause.getMessage());
                return false;
            }

            @Override
            public BigDecimal dominateGold(Map<String, Object> map) {
                return null;
            }

            @Override
            public Long dominateIntegral(Map<String, Object> map) {
                return null;
            }

            @Override
            public BigDecimal BackDominateGold(HttpServletRequest request) {
                return null;
            }

            @Override
            public Long BackDominateIntegral(HttpServletRequest request) {
                return null;
            }

            @Override
            public boolean infiniteVIPHall(Long id) {
                return false;
            }

            @Override
            public boolean audit(String orderNum) {
                return false;
            }

            @Override
            public boolean manageAudit(Map<String, Object> map) {
                return false;
            }

            @Override
            public R<AjaxResult> addCustomerRightdetail(CustomerRightdetail customerRightdetail) {
                return R.fail("新增会员权益失败" + cause.getMessage());
            }

            @Override
            public BankCard selectBankCardBytBankCardId(Long bankCardId) {
                log.error("查询会员已绑定银行卡信息失败", cause.getMessage());
                return null;
            }

            @Override
            public List<BankCard> selectBankCardByMemberId(Map<String, Object> map) {
                log.error("获取会员已绑定银行卡信息失败", cause.getMessage());
                return null;
            }

            @Override
            public List<CustomerTraveler> CustomerTravelerList(Long memberId) {
                log.error("查询旅客信息失败", cause.getMessage());
                return null;
            }

            @Override
            public R<CommonTravelersDto> queryByCustomerIdCommon(Long customerId) {
                return R.fail("获取乘客信息失败" + cause.getMessage());
            }

//            @Override
//            public R<CommonTravelersVo> list(CommonTravelersVo commonTravelers) {
//                return R.fail("获取乘客列表信息失败" + cause.getMessage());
//            }
//
//            @Override
//            public R<Integer> add(CommonTravelersVo commonTravelers) {
//                return R.fail("添加乘客失败" + cause.getMessage());
//            }
//
//            @Override
//            public R<Integer> edit(CommonTravelersVo commonTravelers) {
//                return R.fail("修改乘客信息失败" + cause.getMessage());
//            }
//
//            @Override
//            public R<Integer> remove(Long[] commonTrvelersIds) {
//                return R.fail("删除乘客信息失败" + cause.getMessage());
//            }


            /*@Override
            public String verificationSmsLoginCode(String state, int count) {
                log.error("获取验证码失败", cause.getMessage());
                return null;
            }*/
        };
    }
}
